@echo off
echo ==========================================
echo   Converting OS Image to VMware Format
echo ==========================================
echo.

REM 检查是否存在os-image.bin
if not exist os-image.bin (
    echo [ERROR] os-image.bin not found!
    echo Please run build.bat first.
    pause
    exit /b 1
)

REM 查找qemu-img.exe
set QEMU_IMG=qemu-img.exe

REM 尝试常见安装路径
if exist "C:\Program Files\qemu\qemu-img.exe" set QEMU_IMG=C:\Program Files\qemu\qemu-img.exe
if exist "C:\Program Files (x86)\qemu\qemu-img.exe" set QEMU_IMG=C:\Program Files (x86)\qemu\qemu-img.exe

echo [INFO] Using qemu-img: %QEMU_IMG%
echo [INFO] Converting to VMDK format...
echo.

"%QEMU_IMG%" convert -f raw -O vmdk os-image.bin os-disk.vmdk

if exist os-disk.vmdk (
    echo [OK] Conversion successful!
    echo [OK] Created: os-disk.vmdk
    echo.
    dir os-disk.vmdk
    echo.
    echo ==========================================
    echo   Next Steps to Run in VMware:
    echo ==========================================
    echo.
    echo 1. Open VMware Workstation/Player
    echo 2. Create New Virtual Machine
    echo 3. Select "Custom" configuration
    echo 4. Guest OS: "Other" - "Other"
    echo 5. Firmware: "BIOS" (NOT UEFI!)
    echo 6. Memory: 128 MB or more
    echo 7. Disk: Use existing disk - select os-disk.vmdk
    echo 8. Start the VM and enjoy!
    echo.
) else (
    echo [ERROR] Conversion failed!
    echo.
    echo Possible reasons:
    echo - qemu-img not found in PATH
    echo - QEMU not installed
    echo.
    echo Solutions:
    echo 1. Install QEMU from: https://qemu.weilnetz.de/w64/
    echo 2. Add QEMU to PATH
    echo 3. Or manually convert using VirtualBox/other tools
    echo.
)

pause

